/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package admin;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.DataWrapper;
import model.Inventory;

/**
 *
 * @author moustafa
 */
public class SupplementInv extends HttpServlet {

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{
        DataWrapper wrapper = DataWrapper.getInstance();
        ArrayList<Inventory> defficientInvs = (ArrayList<Inventory>)request.getSession().getAttribute("defficiencies");
        int defficientIndex = Integer.parseInt(request.getParameter("deff_index"));
        Inventory defficientInv = defficientInvs.get(defficientIndex);
        ArrayList<Inventory> suppInvs = wrapper.getRecoveryInventories(defficientInv, wrapper.getConnection());
        request.getSession().setAttribute("supplementaries", suppInvs);
        request.getSession().setAttribute("deff_index", defficientIndex);
        getServletContext().getRequestDispatcher("/admin_pages/supplementaries.jsp").forward(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException{
        
    }

}
